//1. ajax


function CreateAjx(url, cb) {
    let xhr = new XMLHttpRequest();
    xhr.open("get", url);
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4) {
            if (xhr.status == 200) {
                //拿到数据
                xhr.responseText;
                cb(xhr.responseText);
            }
        }
    }
    xhr.send();
}


CreateAjx("a", (dataA) => {
    console.log(dataA);
    CreateAjx("b", (dataB) => {
        console.log(dataB);
        CreateAjx("c", (datac) => {
            console.log(datac);
        })
    })
})


function CretePromise(url) {
    let p = new Promise((resolve, reject) => {
        let xhr = new XMLHttpRequest();
        xhr.open("get", url);
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    //拿到数据
                    resolve(xhr.responseText)
                } else {
                    reject()
                }
            }
        }
        xhr.send();
    })
    return p;
}



CretePromise("urlA").then((dataA) => {
    return CretePromise("urlB")
}).then((dataB) => {
    return CretePromise("urlC")
}).then((datac) => {

})

async function ajaxAll() {
    let dataA = await CretePromise("urlA");
    let datab = await CretePromise("urlB")
    let dataC = await CretePromise("urlC")
}